home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / DIEXTRAC.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  3KB  |  119 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    diextrac.c
  5. //   Title:    Data File I/O Library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains to extract data from a data file to an external file.
  25. //
  26. //    The code in this module should be written entirely in C. 
  27. //    Do not use any C++ constructs.
  28. //
  29. //    This module is portable to:
  30. //        DOS 3.X+
  31. //        MS Windows 3.X+
  32. //        OS/2 2.X+
  33. //        OS/2 2.0 PM
  34. //        SCO UNIX.
  35. //
  36. //    The following compilers are supported:
  37. //        MSC 6.0A
  38. //        MSC/C++ 7.0
  39. //        Borland C++ 3.1 for DOS
  40. //        Borland C++ 1.0 for OS/2 2.X
  41. //        SCO UNIX cc
  42. //
  43. //----------------------------------------------------------------------------
  44. #include <di.h>
  45.  
  46.  
  47. //----------------------------------------------------------------------------
  48. //   Description:    Extract data to an external file.
  49. //    Parameters:    hlf        Logical file handle.
  50. //                        pcszFile    File name to extract to
  51. //       Returns:    TRUE if successful.
  52. //----------------------------------------------------------------------------
  53. BOOL FN_E DioExtract(HLF hlf, PCSZ pcszFile)
  54. {
  55.     FPOS fsize;
  56.     FLAG16 fs = FL_CREATE|FL_TRUNCATE|FL_READWRITE|FL_DENYREADWRITE|FL_BINARY;
  57.     HF hf;
  58.  
  59.     if (!DioGetSize(hlf, &fsize) || !DioSeek(hlf, 0))
  60.         return FALSE;
  61.                                                     // Open external file
  62.     if (!FileOpen(&hf, pcszFile, fs, NULL))
  63.         return FALSE;
  64.                                                     // Copy data
  65.     if (!FileCopy(hf, 0, di.logical[hlf].hf, di.logical[hlf].fbase, fsize))
  66.         {
  67.         FileClose(hf);
  68.         return FALSE;
  69.         }
  70.     FileClose(hf);
  71.     return TRUE;
  72. }
  73.  
  74.  
  75. //----------------------------------------------------------------------------
  76. //   Description:    Extract data to an external file.
  77. //    Parameters:    pcsz            Physical file name
  78. //                        pcszLogical    Logical file name
  79. //                        usType        File type
  80. //                        pcszFile        File name to extract to
  81. //       Returns:    TRUE if successful.
  82. //----------------------------------------------------------------------------
  83. BOOL FN_E DioExtractFile(PCSZ pcsz, PCSZ pcszLogical, USHORT usType, PCSZ pcszFile)
  84. {
  85.     HPF hpf;
  86.     HLF hlf;
  87.     BOOL fUser;
  88.     BOOL fResult = FALSE;
  89.  
  90.     Assert(pcszLogical);
  91.     if (HIUSHORT(pcsz))
  92.         {
  93.         if (!DioOpenPhysical(pcsz, &hpf, FALSE))
  94.             return FALSE;
  95.         fUser = FALSE;
  96.         }
  97.     else
  98.         {
  99.         hpf = LOUSHORT(pcsz);
  100.         Assert(hpf >= 0 && hpf < MAX_PHYSICAL_FILES);
  101.         Assert(di.physical[hpf].fUsed);
  102.         fUser = TRUE;
  103.         }
  104.     if (!DioOpenLogical(pcszLogical, &hlf, usType))
  105.         goto ERROR_EXIT;
  106.  
  107.     if (!DioExtract(hlf, pcszFile))
  108.         goto ERROR_EXIT;
  109.  
  110.     fResult = TRUE;
  111. ERROR_EXIT:
  112.     if (!fUser)
  113.         DioClosePhysical(hpf);
  114.     return fResult;
  115. }
  116. //----------------------------------------------------------------------------
  117. //------------------------------- End of File --------------------------------
  118. //----------------------------------------------------------------------------
  119.